package
{
	
	import flash.display.Shape;
	import flash.events.Event;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.MouseEvent;
	import flash.ui.Mouse;
	import flash.ui.Multitouch;
	import flash.ui.MultitouchInputMode;
	
	/**
	 * ...
	 * @author Pedro Passos
	 */
	public class Main extends Sprite
	{
		var c:Connection = new Connection();
		private var drawing:Boolean;
		
		public function Main():void
		{
			addEventListener(Event.ENTER_FRAME, update);
			stage.addEventListener(MouseEvent.MOUSE_DOWN, StartDraw);
			stage.addEventListener(MouseEvent.MOUSE_MOVE, MoveDraw);
			stage.addEventListener(MouseEvent.MOUSE_UP, StopDraw);
			// entry point
		}
		
		private function update(e:Event):void
		{
			if (c.retornoMsg != null)
			{
				trace("oi");
				var aux:Array = new Array();
				aux = c.retornoMsg.split("/");
				var pontX:int;
				var pontY:int;
				pontX = int(aux[1]);
				pontY = int(aux[2]);
				trace(pontX , pontY);
				var s:Pixel = new Pixel();
				s.x = pontX;
				s.y = pontY;
				stage.addChild(s);
				
			}
		}
		
		public function StartDraw(e:MouseEvent):void
		{
			drawing = true;
			c.enviarDesenho(e.localX, e.localY, "lapis");
		}
		
		public function MoveDraw(e:MouseEvent):void
		{
			if(drawing)
			c.enviarDesenho(mouseX, mouseY, "lapis");
		}
			
		public function StopDraw(e:MouseEvent):void
		{
			drawing = false;
		}
		
	
	}

}